#!/bin/bash
## Platform:All Linux Based Platform
## author:Long Tao
## version:1.0
## description:This is clean image
## Company:QuDan
IMAGE_TAG=qudan
app_name=docker_test
# 获取docker 容器id和镜像id
app_stop_id=$(docker ps -a | grep "$app_name" | awk '{print $1 }')
app_delete_id=$(docker ps -a | grep "$app_name" | awk '{print $1 }')
app_image_id=$(docker images | grep "$IMAGE_TAG" | awk '{print $3 }')
echo "镜像id:" "$app_image_id"
echo "容器id:" "$app_stop_id"

# 容器正在运行,停止
if [ "$app_stop_id"x != ""x ]; then
  echo '================正在停止容器==================='
  docker stop "$app_stop_id"

fi
# 删除容器
if [ "$app_delete_id"x != ""x ]; then
  echo '================开始删除容器==================='
  docker rm "$app_delete_id"

fi
sleep 2

# 删除镜像
if [ "$app_image_id"x != ""x ]; then
  echo '================正在删除镜像==================='
  docker rmi "$app_image_id"
fi